package com.flight.trans.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.flight.trans.R;
import com.flight.trans.base.BaseRecyclerAdapter;
import com.flight.trans.base.BaseViewHolder;
import com.flight.trans.bean.LeavePortWarehousingBean.WarehousingData;
import com.flight.trans.global.Constant;
import com.flight.trans.global.ConstantInfo;
import com.flight.trans.util.CommonUtils;

import java.util.List;

/**
 * 出港入库
 */
public class LeavePortWarehousingAdapter extends BaseRecyclerAdapter<WarehousingData> {

    public LeavePortWarehousingAdapter(Context mContext, List<WarehousingData> mList) {
        super(mContext, mList);
    }

    @Override
    public int setContentView() {
        return R.layout.adapter_leave_port_warehousing;
    }

    @Override
    protected void bindData(BaseViewHolder holder, WarehousingData data, int position) {
        RelativeLayout mRlContainerItem = holder.findViewById(R.id.mRlContainerItem);

        TextView mTvOrderNo = holder.findViewById(R.id.mTvOrderNo);
        TextView mTvCount = holder.findViewById(R.id.mTvCount);
        TextView mTvProductName = holder.findViewById(R.id.mTvProductName);
        TextView mTvDestination = holder.findViewById(R.id.mTvDestination);
        TextView mTvFlightNo = holder.findViewById(R.id.mTvFlightNo);
        TextView mTvSender = holder.findViewById(R.id.mTvSender);
        TextView mTvRemarks = holder.findViewById(R.id.mTvRemarks);
        TextView mTvCreateTime = holder.findViewById(R.id.mTvCreateTime);

        CommonUtils.setScreenViewVisible(mTvDestination);
        CommonUtils.setScreenViewVisible(mTvFlightNo);
        CommonUtils.setScreenViewVisible(mTvSender);

        mTvOrderNo.setText(!TextUtils.isEmpty(data.getOrderNo()) ? data.getOrderNo() : "");
        mTvCount.setText(String.valueOf(data.getNum()));
        mTvProductName.setText(!TextUtils.isEmpty(data.getTradeName()) ? data.getTradeName() : "");
        mTvDestination.setText(!TextUtils.isEmpty(data.getDeap()) ? data.getDeap() : "");
        mTvFlightNo.setText(!TextUtils.isEmpty(data.getFlightNo()) ? data.getFlightNo() : "");
        mTvSender.setText(!TextUtils.isEmpty(data.getSenderName()) ? data.getSenderName() : "");
        mTvRemarks.setText(!TextUtils.isEmpty(data.getRemark()) ? data.getRemark() : "");
        mTvCreateTime.setText(CommonUtils.getTimeNorm(data.getOrderTime()));


        mTvOrderNo.setBackground(data.getTransfer() == Constant.Transport_Code ? mContext.getDrawable(R.mipmap.icon_transport) : null);
        mTvOrderNo.setBackground(data.getState() == Constant.PULL_OFF ? mContext.getDrawable(R.mipmap.icon_pull_off) : null);
        mTvOrderNo.setBackground((data.getState() == Constant.PULL_OFF && data.getTransfer() == Constant.Transport_Code) ? mContext.getDrawable(R.mipmap.icon_transport_pull) : null);

        mRlContainerItem.setBackground(mContext.getDrawable(data.isLocked() ? R.color.color_red : R.drawable.selector_cyan_line));
        setOnItemClickListener(mRlContainerItem , position);

        mTvFlightNo.setBackground(ConstantInfo.WIDE_BODY.equals(data.getActshape()) ? mContext.getDrawable(R.mipmap.icon_act_shape) : null);
    }
}
